/*
 * Phase.cpp
 *
 *  Created on: 19 Aug 2011
 *      Author: Allan
 */

#include "Phase.h"

Phase::Phase()
{}

Phase::Phase(const string& name) :
name(name)
{}
	
Phase::Phase(const string& name, const vector<string>& species) :
name(name), species(species), activity_species(species.size())
{}

void
Phase::SetName(const string& name)
{
	this->name = name;
}
	
void
Phase::SetSpecies(const vector<string>& species)
{
	this->species = species;
	
	activity_species.resize(species.size());
}

const unsigned
Phase::GetNumSpecies() const 
{
	return species.size();
}

const string
Phase::GetName() const 
{
	return name;
}

const vector<string>&
Phase::GetSpecies() const 
{
	return species;
}

const VectorXd
Phase::MolarFractions(const VectorXd& n) const 
{
	return n/n.sum();
}

const VectorXd
Phase::Activities(double T, double P, const VectorXd& n) const
{
	const unsigned num_species = n.rows();
	
	VectorXd a(num_species);
	
	for(unsigned i = 0; i < num_species; ++i) 
		a[i] = activity_species[i]->activity(T, P, n);
	
	return a;
}

const VectorXd
Phase::ActivityCoefficients(double T, double P, const VectorXd& n) const
{
	const unsigned num_species = n.rows();
	
	VectorXd g(num_species);
	
	for(unsigned i = 0; i < num_species; ++i) 
		g[i] = activity_species[i]->activityCoefficient(T, P, n);
	
	return g;
}

const MatrixXd
Phase::ActivityDerivatives(double T, double P, const VectorXd& n, const VectorXd& a) const
{
	const unsigned num_species = n.rows();
	
	MatrixXd A(num_species, num_species);
	
	for(unsigned i = 0; i < num_species; ++i)
		A.row(i) = activity_species[i]->activityDerivatives(T, P, n, a);
	
	return A;
}
